<?php

  require_once ("../accesobd.php");
 
include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');

    $id = $_POST["id"];
    
    
            
     if($id){
             $desven = "SELECT  DISTINCT cli.cic,
	cli.nombrec, 
	cli.apec, 
	cli.fnacimientoc,
	cli.dirc, 
	tlf.tlfc, 
	mail.emailc, 
	cli.trabajo, 
	cli.ingreso, 
	cli.factu,
	veh.modelo, 
	fact.femision, 
	fact.tipopago
FROM 	cliente as cli, 
	tlfcliente as tlf, 
	emailcliente as mail, 
	vehiculo as veh, 
	factura as fact
WHERE 	cli.cic = tlf.cic
AND 	cli.cic = mail.cic
AND 	cli.cic = fact.cic
AND	fact.idveh = veh.idveh
AND     cli.cic = $id;";
             
             $desven2="SELECT  DISTINCT cli.cic,
	cli.nombrec, 
	cli.apec, 
	cli.fnacimientoc,
	cli.dirc, 
	tlf.tlfc, 
	mail.emailc, 
	cli.trabajo, 
	cli.ingreso, 
	cli.factu
FROM 	cliente as cli, 
	tlfcliente as tlf, 
	emailcliente as mail, 
	factura as fact
WHERE 	cli.cic = tlf.cic
AND 	cli.cic = mail.cic
AND 	cli.cic <> fact.cic
AND     cli.cic = $id;";
     }   else{     
               
 
    $desven = "SELECT  DISTINCT cli.cic,
	cli.nombrec, 
	cli.apec, 
	cli.fnacimientoc,
	cli.dirc, 
	tlf.tlfc, 
	mail.emailc, 
	cli.trabajo, 
	cli.ingreso, 
	cli.factu,
	veh.modelo, 
	fact.femision, 
	fact.tipopago
FROM 	cliente as cli, 
	tlfcliente as tlf, 
	emailcliente as mail, 
	vehiculo as veh, 
	factura as fact
WHERE 	cli.cic = tlf.cic
AND 	cli.cic = mail.cic
AND 	cli.cic = fact.cic
AND	fact.idveh = veh.idveh;";
    
    $desven2="SELECT  DISTINCT cli.cic,
	cli.nombrec, 
	cli.apec, 
	cli.fnacimientoc,
	cli.dirc, 
	tlf.tlfc, 
	mail.emailc, 
	cli.trabajo, 
	cli.ingreso, 
	cli.factu
FROM 	cliente as cli, 
	tlfcliente as tlf, 
	emailcliente as mail, 
	factura as fact
WHERE 	cli.cic = tlf.cic
AND 	cli.cic = mail.cic
AND 	cli.cic <> fact.cic;";
     }
    $query2 = pg_query($conex,$desven2) or die('Consulta fallida: ' . pg_last_error());
    $query = pg_query($desven);
        // Redireccion
        pg_close($conex);
        //header("Location: ../../admin/gestionmesas.php")
     
  
     $cuerpo.= "<img src='../img/logo.png' /> <tr>
                        <td colspan='9' align='center'>Clientes</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
                               


                                <th>Cedula</th>
                                <th>Nombre</th>
                                <th>Apellido</th>
                                <th>Fecha de nacimiento</th>
                                <th>Direccion</th>
                                <th>Telefono</th>
                                <th>Email</th>
                                <th>Trabajo</th>
                                <th>Ingreso</th>
                                <th>Ultima Act</th>
                                 <th>Modelo</th>
                                <th>Fecha Compra</th>
                                <th>Tipo de Pago</th>
                                
                                
                               
                        </tr>
                      </thead>"?>
   <?php
        
         while ($linea = pg_fetch_array($query2, null, PGSQL_ASSOC)) {
                    //Guardando tuplas en el pdf
             

                    $cuerpo.= "
                        <tr>
                        <td> ".$linea['cic']."</td>
                        <td> ".$linea['nombrec']."</td>
                        <td> ".$linea['apec']." </td>
                        <td> ".$linea['fnacimientoc']." </td>
                        <td> ".$linea['dirc']."</td>
                        <td> ".$linea['tlfc']." </td>
                        <td> ".$linea['emailc']."</td>
                        <td> ".$linea['trabajo']."</td>             
                        <td> ".$linea['ingreso']." </td>         
                        <td> ".$linea['factu']." </td> 
                        <td> ".''."</td>             
                        <td> ".' '." </td>         
                        <td> ".' '." </td>
                        </tr>";
         }  
         
           while ($linea2 = pg_fetch_array($query, null, PGSQL_ASSOC)) {
                    //Guardando tuplas en el pdf
             

                    $cuerpo.= "
                        <tr>
                        <td> ".$linea2['cic']."</td>
                        <td> ".$linea2['nombrec']."</td>
                        <td> ".$linea2['apec']." </td>
                        <td> ".$linea2['fnacimientoc']." </td>
                        <td> ".$linea2['dirc']."</td>
                        <td> ".$linea2['tlfc']." </td>
                        <td> ".$linea2['emailc']."</td>
                        <td> ".$linea2['trabajo']."</td>             
                        <td> ".$linea2['ingreso']." </td>         
                        <td> ".$linea2['factu']." </td> 
                        <td> ".$linea2['modelo']."</td>             
                        <td> ".$linea2['femision']." </td>         
                        <td> ".$linea2['tipopago']." </td>
                        </tr>";
         }
                 $cuerpo.= "</table>";
                
              crear_pdf($cuerpo,'Cliente');
              
     
?>